/*
 * -------------------------------------------------------------------------------------------------------*
 * SBS Priceboard V2.0
 * Copyright (C) 2008 Unicom Vietnam JSC
 * -------------------------------------------------------------------------------------------------------* 
 * HeadURL: http://192.168.1.4/svn/priceboard/trunk/SBS_PriceboardV2/front-end/end-user/i_priceboard/
 * LastChangeBy: quanhm
 * LastChangeDate: Sep 1, 2008
 */
package com.unicom.priceboard.data.vo;

import com.unicom.priceboard.thread.SecurityThread;
import com.unicom.priceboard.thread.TimerThread;
import com.unicom.priceboard.util.HTML_Producer;
import com.unicom.priceboard.util.Util;

/**
 * Creation date: Sep 1, 2008
 * @author quanhm
 */
public class IntraStock {
	private String symbol;
	private double match_price;
	private int total_vol;
	private double change;
	private String time_point;
	private String market_code;
	private String date;
	
	private double best1Offer;
	private double best2Offer;
	private double best3Offer;
	private int best1OfferVol;
	private int best2OfferVol;
	private int best3OfferVol;
	
	private double best1Bid;
	private double best2Bid;
	private double best3Bid;
	private int best1BidVol;
	private int best2BidVol;
	private int best3BidVol;
	
	/**
	 * Generate with a HOSE stock's information
	 * <b>All volume will have to be multiplied by 10<b>
	 * @param hoStock
	 */
	public IntraStock(LeElement leElement) {
		this.market_code = "hose";
		this.symbol = SecurityThread.mpStockNo.get((short)leElement.getStockNo());
		this.match_price = (double)leElement.getPrice()/100;
		this.total_vol = leElement.getAccumulatedVol()*10;
		
		String t = String.valueOf(leElement.getTime());
		this.time_point = t.length()==6?t:"0"+t;
		
		HoStock hoStock = SecurityThread.currentStockList.get(this.symbol);
		if(hoStock!=null) {
			this.change = Double.parseDouble(hoStock.getChange());
			this.best1Bid = Double.parseDouble(hoStock.getBest1Bid().replaceAll(",", ""));
			this.best2Bid = Double.parseDouble(hoStock.getBest2Bid().replaceAll(",", ""));
			this.best3Bid = Double.parseDouble(hoStock.getBest3Bid().replaceAll(",", ""));
			this.best1BidVol = Integer.parseInt(hoStock.getBest1BidVolume().replace(",", ""))*10;
			this.best2BidVol = Integer.parseInt(hoStock.getBest2BidVolume().replace(",", ""))*10;
			this.best3BidVol = Integer.parseInt(hoStock.getBest3BidVolume().replace(",", ""))*10;
			this.best1Offer = Double.parseDouble(hoStock.getBest1Offer().replaceAll(",", ""));
			this.best2Offer = Double.parseDouble(hoStock.getBest2Offer().replaceAll(",", ""));
			this.best3Offer = Double.parseDouble(hoStock.getBest3Offer().replaceAll(",", ""));
			this.best1OfferVol = Integer.parseInt(hoStock.getBest1OfferVolume().replace(",", ""))*10;
			this.best2OfferVol = Integer.parseInt(hoStock.getBest2OfferVolume().replace(",", ""))*10;
			this.best3OfferVol = Integer.parseInt(hoStock.getBest3OfferVolume().replace(",", ""))*10;
		}
		
		setDate(Util.getCurrentDate("yyyy-mm-dd"));
	}
	
	/**
	 * Generate with a HASTC stock's informations
	 * @param haStock
	 */
	public IntraStock(HaStock haStock) {
		this.market_code = "hastc";
		this.symbol = haStock.getSymbol();
		this.match_price = haStock.getPrice()/HTML_Producer.hastc_unit;
		this.total_vol = haStock.getTotalVol();
		this.change = haStock.getChange();
		
		String secs = TimerThread.SECONDS>=10?String.valueOf(TimerThread.SECONDS):"0"+String.valueOf(TimerThread.SECONDS);
		String t = String.valueOf(TimerThread.CURRENT_TIME)+secs;
		this.time_point = t.length()==6?t:"0"+t;
		
		this.best1Bid = haStock.getBest1Bid()/HTML_Producer.hastc_unit;
		this.best2Bid = haStock.getBest2Bid()/HTML_Producer.hastc_unit;
		this.best3Bid = haStock.getBest3Bid()/HTML_Producer.hastc_unit;
		this.best1BidVol = haStock.getBest1BidVolume();
		this.best2BidVol = haStock.getBest2BidVolume();
		this.best3BidVol = haStock.getBest3BidVolume();
		this.best1Offer = haStock.getBest1Offer()/HTML_Producer.hastc_unit;
		this.best2Offer = haStock.getBest2Offer()/HTML_Producer.hastc_unit;
		this.best3Offer = haStock.getBest3Offer()/HTML_Producer.hastc_unit;
		this.best1OfferVol = haStock.getBest1OfferVolume();
		this.best2OfferVol = haStock.getBest2OfferVolume();
		this.best3OfferVol = haStock.getBest3OfferVolume();
		
		setDate(Util.getCurrentDate("yyyy-mm-dd"));
	}
	
	/**
	 * @return the symbol
	 */
	public String getSymbol() {
		return symbol;
	}
	
	/**
	 * @return the match_price
	 */
	public double getMatch_price() {
		return match_price;
	}
	
	/**
	 * @return the total_vol
	 */
	public int getTotal_vol() {
		return total_vol;
	}
	
	/**
	 * @return the change
	 */
	public double getChange() {
		return change;
	}
	
	/**
	 * @return the time_point
	 */
	public String getTime_point() {
		return time_point;
	}
	
	/**
	 * @return the market_code
	 */
	public String getMarket_code() {
		return market_code;
	}
	
	/**
	 * @return the best1Offer
	 */
	public double getBest1Offer() {
		return best1Offer;
	}
	
	/**
	 * @return the best2Offer
	 */
	public double getBest2Offer() {
		return best2Offer;
	}
	
	/**
	 * @return the best3Offer
	 */
	public double getBest3Offer() {
		return best3Offer;
	}
	
	/**
	 * @return the best1OfferVol
	 */
	public int getBest1OfferVol() {
		return best1OfferVol;
	}
	
	/**
	 * @return the best2OfferVol
	 */
	public int getBest2OfferVol() {
		return best2OfferVol;
	}
	
	/**
	 * @return the best3OfferVol
	 */
	public int getBest3OfferVol() {
		return best3OfferVol;
	}
	
	/**
	 * @return the best1Bid
	 */
	public double getBest1Bid() {
		return best1Bid;
	}
	
	/**
	 * @return the best2Bid
	 */
	public double getBest2Bid() {
		return best2Bid;
	}
	
	/**
	 * @return the best3Bid
	 */
	public double getBest3Bid() {
		return best3Bid;
	}
	
	/**
	 * @return the best1BidVol
	 */
	public int getBest1BidVol() {
		return best1BidVol;
	}
	
	/**
	 * @return the best2BidVol
	 */
	public int getBest2BidVol() {
		return best2BidVol;
	}
	/**
	 * @return the best3BidVol
	 */
	public int getBest3BidVol() {
		return best3BidVol;
	}

	/**
	 * @return the date
	 */
	public String getDate() {
		return date;
	}

	/**
	 * @param date the date to set
	 */
	public void setDate(String date) {
		this.date = date;
	}
}
